package reponsitory;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import people.People;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * reponsitory
 *
 * 2018/6/11-7:00
 * 2018
 * Created by wuqiang on 2018/6/11.
 */
@Repository
public class JdbcReponsitory implements PeopleRepository {

    @Autowired
    private JdbcOperations jdbcOperations;

    @Override
    public People findAll(){
        String sql="select username from users";
        People people = jdbcOperations.queryForObject(sql, new RowMapper<People>() {
            @Override public People mapRow(ResultSet resultSet, int i) throws SQLException {
                People people = new People();
                people.setName(resultSet.getString("username"));
                return people;
            }
        });
        return people;
    }
}
